﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ComponentModel;

namespace LLServer
{
    [DataContract]
    public class Client : INotifyPropertyChanged, IComparer<Client>
    {
        string _password;
        string _username;
        bool _isAvailable;
        string _captainName;
        int _fraction;
        int _captainId;

        [DataMember(IsRequired = true)]
        public string CaptainName
        {
            get { return _captainName; }
            set { 
                _captainName = value;
                this.OnPropertyChanged("CaptainName");
            }
        }

        [DataMember(IsRequired = true)]
        public bool IsAvailable
        {
            get { return _isAvailable; }
            set { 
                _isAvailable = value;
                this.OnPropertyChanged("IsAvailable");
            }
        }

        [DataMember(IsRequired = true)]
        public string Password
        {
            get { return _password; }
            set
            {
                _password = value;
                this.OnPropertyChanged("Password");
            }
        }

        [DataMember(IsRequired = true)]
        public string Username
        {
            get { return _username; }
            set { _username = value; }
        }

        [DataMember(IsRequired = true)]
        public int Fraction
        {
            get { return _fraction; }
            set { 
                _fraction = value;
                this.OnPropertyChanged("Fraction");
            }
        }

        [DataMember(IsRequired = true)]
        public int CaptainId
        {
            get { return _captainId; }
            set { 
                _captainId = value;
                this.OnPropertyChanged("CaptainId");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propName)
        {
            if (PropertyChanged != null)
            {
                PropertyChangedEventArgs e = new PropertyChangedEventArgs(propName);

                PropertyChanged(this, e);
            }
        }

        public int Compare(Client x, Client y)
        {
            return string.Compare(x.Username, y.Username);
        }
    }
}
